home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / src / compiler / Stack.sml < prev    next >
Encoding:
Text File  |  1997-08-18  |  424 b   |  34 lines  |  [TEXT/R*ch]

  1. (* Stack.sml *)
  2.  
  3. open List;
  4.  
  5. type 'a t = 'a list ref;
  6.  
  7. exception Empty;
  8.  
  9. fun new() = ref [];
  10.  
  11. fun push x s = (s := x :: !s);
  12.  
  13. fun pop s =
  14.   case !s of
  15.       [] => raise Empty
  16.     | x :: xs => (s := xs; x)
  17. ;
  18.  
  19. fun peek s =
  20.   case !s of
  21.       [] => raise Empty
  22.     | x :: xs => x
  23. ;
  24.  
  25. fun update x s =
  26.   case !s of
  27.       [] => raise Empty
  28.     | _ :: xs => (s := x :: xs)
  29. ;
  30.  
  31. fun null s = List.null (!s);
  32.  
  33. fun clear s = (s := []);
  34.